package com.example.theorygame;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

import com.example.theorygame.layer.WelcomeLayer;
import com.example.theorygame.music.mp;
import com.example.theorygame.music.mpt;
import com.example.theorygame.music.vpt;

import org.cocos2d.layers.CCScene;
import org.cocos2d.nodes.CCDirector;
import org.cocos2d.opengl.CCGLSurfaceView;

public class MainActivity extends Activity {
    private CCDirector director;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //应聘
        CCGLSurfaceView view = new CCGLSurfaceView(this);
        //设置主屏幕
        setContentView(view);

        //导演
        director = CCDirector.sharedDirector();
        //导演和荧屏关联
        director.attachInView(view);
        //设置帧数 FPS
        director.setDisplayFPS(true);
        //设置横屏
        director.setDeviceOrientation(CCDirector.kCCDeviceOrientationLandscapeLeft);
        //设置尺寸大小
        director.setScreenSize(480, 320);

        /**
         * 设置场景*/
        CCScene scene = CCScene.node();
        //场景添加图层
        WelcomeLayer layer = new WelcomeLayer();
//		FourthLayer layer = new FourthLayer();
//		ThirdLayer layer = new ThirdLayer();
//		FifthLayer layer = new FifthLayer();
//		SixthLayer layer = new SixthLayer();
        scene.addChild(layer);
        mp.initMedia(MainActivity.this);
        new Thread(new mpt()).start();
        vpt.init(MainActivity.this);

        //导演运行场景
        director.runWithScene(scene);
//        director.replaceScene(scene);

    }

    //导演暂停
    protected void onPause() {
        super.onPause();
        System.out.println("导演暂停");
        director.pause();
    }

    //导演重启
    protected void onResume() {
        super.onResume();
        System.out.println("导演重启");
        director.resume();
    }

    //导演销毁
    protected void onDestory() {
        super.onDestroy();
        System.out.println("导演销毁");
        director.end();
        System.exit(0);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}